﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LED_Editor.ControllerProgramming
{
    public class ControllerProgrammingStrategyBase : IControllerProgrammingStrategy
    {
        public ControllerProgrammingStrategyBase()
        {
            State = ControllerState.Begin;
        }

        #region IControllerProgrammingStrategy Members

        public event LoggingEventHandler Logging;

        public virtual void OpenConnection()
        {
            Log("Контроллер {0}. Соединение открыто.", Address.ToString());
        }

        public virtual void CloseConnection()
        {
            Log("Контроллер {0}. Соединение закрыто.", Address.ToString());
        }

        public virtual void Programme(IEnumerable<LED_Editor.Model.FrameStruct> frames)
        {
            throw new NotImplementedException();
        }
        private ControllerState _state;
        public virtual ControllerState State
        {
            get { return _state; }
            protected set {
                if (_state != value)
                {
                    Log("     Состояние: {0} -> {1} ", _state.ToString(), value.ToString());
                }
                _state = value;
            }
        }

        public virtual bool IsReadyForProgramming
        {
            get { throw new NotImplementedException(); }
        }

        public virtual bool IsOpen
        {
            get { throw new NotImplementedException(); }
        }

        public virtual void SendQuery(byte[] query)
        {
            throw new NotImplementedException();
        }

        public virtual void SendQuery(object query)
        {
            throw new NotImplementedException();
        }

        public virtual void SendFrame(LED_Editor.Model.FrameStruct frame)
        {
            throw new NotImplementedException();
        }

        public virtual object WaitAnswer()
        {
            throw new NotImplementedException();
        }


        protected byte _address;
        public virtual byte Address
        {
            get
            {
               return _address;
            }
            set
            {
                _address = value;
            }
        }

        public virtual int Timeout
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        protected virtual void OnLogging(string message)
        {
            if (Logging != null)
            {
                Logging(this, new LogEventArgs(message));
            }
        }

        protected virtual void Log(string message)
        {
            OnLogging(message);
        }

        public virtual void Log(string message, params string[] args)
        {
            Log(string.Format(message, args));
        }
    }
}
